<?php
declare (strict_types = 1);

namespace app\listener;

use think\swoole\Websocket as Ws;

class Websocket
{
	
	public $websocket;

    public function __construct(Ws $websocket)
    {
        $this->websocket = $websocket;
    }


    /**
     * 事件监听处理
     *
     * @return mixed
     */
    public function handle($event)
    {
        var_dump($event['fd']);
        var_dump($event['packet']);
      
    	$room = '2';
    	
    	//进入房间
        $this->websocket->join($room);
        
        //离开房间
        //$this->websocket->leave($room);
		
		//发给房间所有人或者指定人 Set multiple recipients fd or room names.
		$this->websocket->to($room)->emit("callback", $event);
			
		//发给所有人
		//$this->websocket->broadcast()->emit("callback", $event);
		
		//发给当前fd
       // $this->websocket->emit("callback", $event);

    }    
}
